/***
    Amrita ITEWS - Copyright (C) 2009 Amrita Vishwa Vidyapeetham, Amritapuri.
                                       (http://www.amrita.edu)
    ***************************************************************************
    This file is part of the Amrita ITEWS distribution.
    Amrita ITEWS is free software; you can redistribute it and/or modify it
    under the terms of the GNU General Public License (version 2) as published
    by the Free Software Foundation AND MODIFIED BY the Amrita ITEWS exception.
    ***NOTE*** The exception to the GPL is included to allow you to distribute
    a combined work that includes Amrita ITEWS without being obliged to provide
    the source code for proprietary components outside of the Amrita ITEWS
    software. Amrita ITEWS is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
    Public License for more details. You should have received a copy of the GNU
    General Public License and the Amrita ITEWS license exception along with
    Amrita ITEWS if not then it can be viewed here:
    http://itews.amrita.ac.in/license.html.


    Documentation, latest information, license and contact details are at:
    http://itews.amrita.ac.in/


    Amrita ITEWS source code can be found at:
    http://code.google.com/p/itews


    The initial code-base of Amrita ITEWS was developed by Amrita Vishwa
    Vidyapeetham as part of the project titled,"Intelligent & Interactive
    Telematics using Emerging Wireless Technologies for Transport Systems
    (ITEWS)" sponsored by Technology Information Forecasting and Assessment
    Council (TIFAC), India.
***/

/*! \file thread_eventq.h
    \brief Thread Event Queue Service Provider Interface Header File.
*/

#ifndef THREAD_EVENTQ_H_
#define THREAD_EVENTQ_H_

#include <eventq.h>


/*! \brief Create Thread Event Type Flag,
 PUT event,
 param (I) - address of thread_param_t,
 buf - none.
 */
#define     EVT_THREAD_CREATE       0x00


/*! \brief Exit Thread Event Type Flag,
 PUT event,
 param (O) - address of int32 variable to
  which exit status of thread is stored,
 buf - none.
 * */
#define     EVT_THREAD_EXIT         0x01

/*
 * Following events are tentative only.  Do not use
 * them in the application.
 */
/*! \brief Set Thread Detach State Event Type Flag.*/
#define     EVT_THREAD_SET_DSTATE   0x02

/*! \brief Set Thread Sched Policy Event Type Flag.*/
#define     EVT_THREAD_SET_SPOLICY  0x03

/*! \brief Set Thread Sched Param Event Type Flag.*/
#define     EVT_THREAD_SET_SPARAM   0x04

/*! \brief Set Thread Inherit Schedule Event Type Flag.*/
#define     EVT_THREAD_SET_ISCHED   0x05

/*! \brief Set Thread Scope Event Type Flag.*/
#define     EVT_THREAD_SET_SCOPE    0x06

/*! \brief Get Thread Detach State Event Type Flag.*/
#define     EVT_THREAD_GET_DSTATE   0x07

/*! \brief Get Thread Sched Policy Event Type Flag.*/
#define     EVT_THREAD_GET_SPOLICY  0x08

/*! \brief Get Thread Sched Param Event Type Flag.*/
#define     EVT_THREAD_GET_SPARAM   0x09

/*! \brief Get Thread Inherit Schedule Event Type Flag.*/
#define     EVT_THREAD_GET_ISCHED   0x0A

/*! \brief Get Thread Scope Event Type Flag.*/
#define     EVT_THREAD_GET_SCOPE    0x0B

/*! \brief Thread Joinable State Flag. */
#define     THREAD_STATE_JOINABLE   0x00

/*! \brief Thread Detach State Flag. */
#define     THREAD_STATE_DETACH     0x01

/*! \brief Thread Joinable State Flag. */
#define     THREAD_STATE_JOINABLE   0x00

/*! \brief Thread Detach State Flag. */
#define     THREAD_STATE_DETACH     0x01

/*! \brief Thread Explicit Sched Flag. */
#define     THREAD_EXPLICIT_SCHED   0x00

/*! \brief Thread Inherit Sched Flag. */
#define     THREAD_INHERIT_SCHED    0x01

/*! \brief Thread System Scope Flag. */
#define     THREAD_SCOPE_SYSTEM     0x00

/*! \brief Thread Process Scope Flag. */
#define     THREAD_SCOPE_PROCESS    0x01

/*! \brief Thread Sched Other (Non Real Time, Non FIFO) Flag. */
#define     THREAD_SCHED_OTHER      0x00

/*! \brief Thread Sched FIFO Flag. */
#define     THREAD_SCHED_FIFO       0x01

/*! \brief Thread Sched RR Flag. */
#define     THREAD_SCHED_RR         0x02

/*! \brief Thread Relative Priority Flag for backgroung thread (low priority). */
#define THREAD_PRI_BACKGROUND_TASK  0

/*! \brief Thread Relative Priority Flag for Active thread. */
#define THREAD_PRI_ACTIVE_TASK      1

/*! \brief Thread Relative Priority Flag for Real Time thread (high priority). */
#define THREAD_PRI_REALTIME_TASK    2

/*! \brief Structure for Holding Thread Event Param Information.*/
typedef struct
{
    /*! \brief Thread Function to execute.*/
    void * (*thread_func)(void *arg);

    /*! \brief Argument to Thread Function.*/
    void *arg;

    /*! \brief Priority*/
    int32 priority;

}thread_param_t;



/*! \brief Thread Event Queue Operation Structure Global Variable.*/
extern eventq_ops_t thread_eventq_ops;


/*SPI*/
STATUS thread_eventq_open       ( eventq_ctx_t *, const char *eventq_name );
STATUS thread_eventq_close      ( eventq_ctx_t * );
STATUS thread_eventq_sync_put   ( eventq_ctx_t *, event_t *, HRESULT *res );
STATUS thread_eventq_sync_get   ( eventq_ctx_t *, event_t * );

#endif /*THREAD_EVENTQ_H_*/
